package org.ktjiaoyu.handel;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import java.io.IOException;

/**
 * @author Jane
 * @date 2025-02-11 15:23
 */

public class MyFormLoginSuccessHandler implements AuthenticationSuccessHandler {

    private final String url;

    public MyFormLoginSuccessHandler(String url){
        this.url = url;
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        User user = (User) authentication.getPrincipal();
        System.out.println("权限列表: "+ user.getAuthorities());
        response.sendRedirect(url);
    }
}
